#include <iostream>
#include "thread_pool.h"
#include "creat_html.h"
#include <thread>
#include <chrono>
#include <filesystem>

namespace fs = std::filesystem;

class DickTask : public ThreadPool::Task
{
public:
	ThreadPool::Any Run () override {
		std::this_thread::sleep_for(std::chrono::seconds(2));
		std::cout << " func is being :" <<std::this_thread::get_id() <<std::endl;
		return  ThreadPool::Any(99);
	}
};


void ThreadPools()
{
	ThreadPool::ThreadPool pool;
	// 启动10 个线程
	pool.Start(10);
	DickTask disk;
	ThreadPool::Result result = pool.SubmitTask(std::make_unique<DickTask>());
	int ret = result.Get().Cast<int>();
	std::cout << " ret is"  << ret;
}

void SendHtml()
{
	CreateHtml email;
	email.AddContacts({"recipient1@example.com", "recipient2@example.com"});
	email.AddHtml("<html><body><h1>Hello, World!</h1></body></html>");
	email.Send("smtp.example.com", 587, "your_email@example.com", "your_email@example.com", "your_password");
}


// 获取指定文件夹下的第一层所有文件夹路径
std::vector<std::string> GetSubdirectories(const std::string& path) {
  std::vector<std::string> subdirectories;
  if (!fs::exists(path)) {
    std::cerr << "Error: Path does not exist: " << path << std::endl;
    return subdirectories;
  }

  if (!fs::is_directory(path)) {
    std::cerr << "Error: Path is not a directory: " << path << std::endl;
    return subdirectories;
  }

  for (const auto& entry : fs::directory_iterator(path)) {
    if (fs::is_directory(entry)) {
      subdirectories.push_back(entry.path().string());
    }
  }
  return subdirectories;
}


// 获取文件夹下所有文件的总大小
uintmax_t GetDirectorySize(const std::string& path) {
  uintmax_t totalSize = 0;
    for (const auto& entry : fs::recursive_directory_iterator(path)) {
      if (fs::is_regular_file(entry)) {
        std::cout << " 11111111111111111111111111111111111111 "<< std::endl;
        totalSize += fs::file_size(entry);
        std::cout << " 2222222222222222222222222222222222222 "<< std::endl;
      }
//      std::cout << " >>>>>>>>>>>>>>>>>>>>>>>>>>> :" << entry.path() << "      " << totalSize << std::endl;
    }
  return totalSize;
}

void Test()
{
  std::string targetFolder = "D:\\"; // 指定目录路径

  // 获取第一层文件夹路径
  std::vector<std::string> subdirectories = GetSubdirectories(targetFolder);

  // 输出所有文件夹路径
  std::cout << "Subdirectories:\n";
  for (const auto& dir : subdirectories) {
    std::cout << dir << std::endl;
  }

  // 获取每个子文件夹的大小并输出
  std::vector<uintmax_t> directorySizes;
  for (const auto& dir : subdirectories) {
    uintmax_t size = GetDirectorySize(dir);
    directorySizes.push_back(size);
  }

  // 输出每个文件夹的大小
  std::cout << "\nDirectory Sizes (in bytes):\n";
  for (size_t i = 0; i < subdirectories.size(); ++i) {
    std::cout << subdirectories[i] << ": " << directorySizes[i] << " bytes" << std::endl;
  }
};
int main() {

  Test();
//  ThreadPools();
//
//  SendHtml();
	return 0;
}
